package com.lwkjgf.workplace.base;

import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;

import androidx.appcompat.app.AppCompatActivity;

import com.lwkjgf.workplace.R;
import com.lwkjgf.workplace.utils.ResString;


/**
 * 所有activity都继承这个类，这里主要做一些各个activity共有的特质
 * 这里实现IViewer接口，继承这个类的Activity都不用再实现IViewer中的接口，而且都能使用里面的接口
 */
public class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        /**
         * 设置界面竖屏
         * */
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        super.onCreate(savedInstanceState);
    }


    ProgressDialog progressDialog;

    public void showProgressDialog(String title, String message) {
        if (progressDialog == null) {
            progressDialog = ProgressDialog.show(
                    this, title.equals("") ? ResString.getString(this,
                            R.string.loading) : title, message.equals("") ?
                            ResString.getString(this,R.string.loading) : message,
                    true, false);
        } else if (progressDialog.isShowing()) {
            progressDialog.setTitle(ResString.getString(this, R.string.loading));
            progressDialog.setMessage(message);
        }
        progressDialog.show();
//        onHandler();
    }

    public void hideProgressDialog() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }

    public void onHandler() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hideProgressDialog();
            }
        }, 10000);
    }

    @Override
    protected void onDestroy() {
        hideProgressDialog();
        super.onDestroy();
    }
}
